import {BASE_URL} from '../ajax.js'

// 添加商品 base_url='https://www.wujiaqi.xyz/supermarket'
export function addgoods_1(filepath,spmc,spdj,basetypeId,shopId) {
	return uni.uploadFile({
/* 							url:'https://www.wujiaqi.xyz/supermarket/supermarket/goods/addGoodsUp?spmc=%E7%B3%96&spdj=12&basetypeId=1509744274371223553&shopID=1001',
 */				            url:'https://www.wujiaqi.xyz/supermarket/supermarket/goods/addGoodsUp'+'?spmc='+spmc+'&spdj='+spdj+'&basetypeId='+basetypeId+'&shopID='+shopId, //
				            filePath: filepath,
				            name: 'file',
				            success: (uploadFileRes) => {
								let pages = getCurrentPages();
								let beforePage = pages[pages.length - 2];
								beforePage.$vm.reFresh = Math.random()
				                console.log(uploadFileRes.data)								
									uni.showToast({
										title:'添加成功'
									})								
								
				            },
										})
										}
export function addgoods_2(filepath, spmc,spdj,basetypeId,appendtypeId,shopId) {
	return uni.uploadFile({
				            url: "https://www.wujiaqi.xyz/supermarket/supermarket/goods/addGoodsUp"+'?spmc='+spmc+'&spdj='+spdj+'&basetypeId='+basetypeId+'&appendtypeId='+appendtypeId+'&shopID='+shopId, //
				            filePath: filepath,
				            name: 'file',
				            success: (uploadFileRes) => {
								let pages = getCurrentPages();
								let beforePage = pages[pages.length - 2];
								beforePage.$vm.reFresh = Math.random()
				                console.log(uploadFileRes.data)
								uni.showToast({
									title:'添加成功'
								})
				            },
										})
										}
/* 重置对象数组里面的key*/										
export function change_key(arr, key) {
	let newArr = [];
	arr.forEach((item, index) => {
	  let newObj = {};
	  for (var i = 0; i < key.length; i++) {
	    newObj[key[i]] = item[Object.keys(item)[i]]
	  }
	  newArr.push(newObj);
	})
	return newArr
				}	
/* 根据类型id匹配名称，arr为对象数组，basetype为对象数组*/					
export function change_arr(arr,basetype) {
	arr.forEach((item, index) => {
	for(var i = 0; i < basetype.length; i++){

		if (item.basetypeId==basetype[i].basetypeId)
		{
			item.basetypeTitle=basetype[i].basetypeTitle
		}
	}

	})
	return arr
				}	
/* 根据类型id匹配名称，将类型id直接替换为类型名称*/													
export function change_coupon(arr,type) {
	arr.forEach((item, index) => {
	for(var i = 0; i < type.length; i++){

		if (item.sytype==type[i].typeId)
		{	
			item.sytype=type[i].typeTitle
		}
	}

	})
	return arr
				}									
export function updatecandidate(items){
			let candidates = []
			let index = items.length
			console.log(index)
		/* 	console.log(items) */
			if (index){
				candidates[0]=items[0].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[1]=items[1].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[2]=items[2].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[3]=items[3].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[4]=items[4].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[5]=items[5].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[6]=items[6].basetypeTitle
				index=index -1;
				console.log(index)
			}
			if (index){
				candidates[7]=items[7].basetypeTitle
				
				index=index -1;
				console.log(index)
			}
			console.log('候选项更新完成')
	return 	candidates
}
export function updateappendcandidate(items){
			let appendcandidates = []
			let index = items.length
			console.log(index)
		/* 	console.log(items) */
			if (index){
				appendcandidates[0]=items[0].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[1]=items[1].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[2]=items[2].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[3]=items[3].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[4]=items[4].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[5]=items[5].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[6]=items[6].appendtypeTitle
				index=index -1;
				console.log(index)
			}
			if (index){
				appendcandidates[7]=items[7].appendtypeTitle
				
				index=index -1;
				console.log(index)
			}
			console.log('活动候选项更新完成')
	/* 		if (index){
				candidates[4]=items[4].basetypeTitle
				
				index=index -1;
				console.log(index)
			} */
	return 	appendcandidates
}
			
/* export function updatebasetype() {
	return uni.request({
			// url:options.url,
			url:BASE_URL+'/supermarket/goods/getBaseType',
			method: 'GET',
			data: {},
			success: (res)=>{
				console.log(res.data.data.items)
				uni.hideLoading()
			},
			fail: (err)=>{
				uni.showToast({
					title: '请求接口失败'
				})
				reject(err)
			}
		})
										} */